#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int t,a[N + 5],b[N + 5],c[N + 5];
int main(){
	freopen ("color.in","r",stdin);
	freopen ("color.out","w",stdout);
	cin >> t;
	while (t --){
		int n,sum = 0;
		cin >> n;
		for (int i = 1;i <= n;i ++) cin >> a[i],b[i] = 0;
		for (int i = 2;i < n;i ++){
			if (a[i - 1] == a[i + 1]) b[i] = 1;
		}
		for (int i = 1;i <= n;i ++){
			bool flag = 0;
			for (int j = i;j >= 1;j --){
				if (b[i] == b[j] && i != j && a[i] == a[j]){
					flag = 1;
					c[i] = a[i];
					break;
				}
			}
			if (!flag) c[i] = 0;
		}
		for (int i = 1;i <= n;i ++) sum += c[i];
		cout << sum << endl;
	}
	return 0;
}
